package com.sharp.oss.controller;

import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import com.sharp.kernel.vo.common.CommonResVO;
import com.sharp.oss.service.BannerService;
import com.sharp.oss.vo.banner.BannerReq;
import com.sharp.oss.vo.banner.BannerRes;
import com.sharp.oss.vo.banner.DeleteBannerReq;
import com.sharp.oss.vo.banner.UpdateBannerReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Title: BannerController
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/7/20 22:43
 * @description Project Name: Seed
 * @Package: com.srct.service.oss.controller
 */
@Api(value = "轮播图", tags = "轮播图")
@RestController("BannerController")
@RequestMapping(value = "/banner")
public class BannerController {
    @Resource
    private BannerService bannerService;

    @RequestMapping(value = "", method = RequestMethod.GET)
    @ApiOperation(value = "获取所有轮播图", notes = "获取所有轮播图")
    public ResponseEntity<Response<List<BannerRes>>> getBanner(BannerReq req) {
        List<BannerRes> res = bannerService.getBanner(req.getType());
        return ResponseHandler.generateResponse(res);
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    @ApiOperation(value = "更新轮播图", notes = "更新轮播图")
    public ResponseEntity<Response<CommonResVO>> updateBanner(@RequestBody UpdateBannerReq req) {
        bannerService.updateBanner(req);
        return ResponseHandler.commonResponse();
    }

    @RequestMapping(value = "", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除轮播图", notes = "删除轮播图")
    public ResponseEntity<Response<CommonResVO>> deleteBanner(@RequestBody DeleteBannerReq req) {
        bannerService.deleteBanner(req);
        return ResponseHandler.commonResponse();
    }
}
